﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapLibrary
{
    public class PageManager<T>
    {

        private List<T> mToTrack;
        private int mNumPerPage;
        private int mCurrPage;

        public PageManager(List<T> toTrack, int numPerPage)
        {
            mToTrack = toTrack;
            mNumPerPage = numPerPage;

            mCurrPage = 1;
        }

        public Page<T> CurrentPage
        {
            get { return new Page<T>(mToTrack, mCurrPage, mNumPerPage); }
        }

        public int CurrentPageNumber
        {
            get { return mCurrPage; }
        }

        public int NumberOfElementsOnCurrentPage
        {
            get
            {
                if (mCurrPage < NumberOfPages || ((mToTrack.Count % mNumPerPage) == 0))
                    return mNumPerPage;
                else
                    return mToTrack.Count % mNumPerPage;
            }
        }

        public void FlipRight()
        {
            if (CanFlipRight)
                mCurrPage += 1;
        }

        public void FlipLeft()
        {
            if (CanFlipLeft)
                mCurrPage -= 1;
        }

        public bool CanFlipRight
        {
            get { return mCurrPage < NumberOfPages; }
        }

        public bool CanFlipLeft
        {
            get { return mCurrPage > 1; }
        }

        public int NumberOfPages
        {
            get 
            {
                if ((mToTrack.Count % mNumPerPage) > 0)
                    return (mToTrack.Count / mNumPerPage) + 1;
                else
                    return (mToTrack.Count / mNumPerPage);
            }
        }
    }
}
